package snowforce;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import snowforce.datatype.PassPointJSON;
import snowforce.storage.PassPointJSONStore;

@Path("/passpoint")
public class PassPointService
{
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public PassPointJSON getPassPointJSON(@QueryParam("level") String levelStr, @QueryParam("index") String indexStr)
	{
		System.out.println("PassPointService");
		System.out.println("levelStr:" + levelStr);
		System.out.println("indexStr:" + indexStr);
		PassPointJSON ret = new PassPointJSON();
		// ret = getDefault();
		int level, index;
		try {
			level = Integer.parseInt(levelStr);
		}
		catch (Exception e) {
			e.printStackTrace();
			ret.setStatus("PARAM_LEVEL_WRONG");
			return ret;
		}
		try {
			index = Integer.parseInt(indexStr);
		}
		catch (Exception e) {
			e.printStackTrace();
			ret.setStatus("PARAM_INDEX_WRONG");
			return ret;
		}
		ret = PassPointJSONStore.getStore().get("" + level).get(index);
		return ret;
	}

	private PassPointJSON getDefault()
	{
		return new PassPointJSON("OK", 5, 2.0f, 1.0f, 0.0f, 0.0f, 0, "", 4000);
	}

}